/*
 * Title:        CloudScheduler Toolkit
 * Description:  a Toolkit for Modeling and Simulation of Job Scheduling and Resource Provisioning in Cloud System
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 * Author:       Fuhui Wu
 *
 * Copyright (c) 2013-2014, The National University of Defense Technology, China
 */

package org.nudt.jCloud.example.basic;

import java.util.ArrayList;
import java.util.List;

import org.nudt.jCloud.infrastructure.HomegeneousCluster;
import org.nudt.jCloud.infrastructure.SlotType;
import org.nudt.jCloud.jobScheduler.AFCFSScheduler;
import org.nudt.jCloud.resourceManager.GeneralShareStateRM;
import org.nudt.jCloud.resourceManager.ResManager;
import org.nudt.jCloud.resourceScaler.ResourceScaler;
import org.nudt.jCloud.resourceScaler.ThresholdScaler;
import org.nudt.jCloud.simulation.CloudSchedSIM;
import org.nudt.jCloud.simulation.SIMTag;
import org.nudt.jCloud.simulation.User;
import org.nudt.jCloud.simulation.UserBroker;
import org.nudt.jCloud.workload.AllJob;
import org.nudt.jCloud.workload.AnyJob;
import org.nudt.jCloud.workload.BatchJob;
import org.nudt.jCloud.workload.Job;
import org.nudt.jCloud.workload.OrderJob;
import org.nudt.jCloud.workload.Task;
import org.nudt.jCloud.workload.Workload;

public class XJob {
	public static void main(String[] args){
		CloudSchedSIM.init("XJob");
		HomegeneousCluster homeCluster = new HomegeneousCluster(20, 1000, 2, 4000, 1000, 200000);
		ResManager monolithicRM = new GeneralShareStateRM("Monolithic", homeCluster);
		UserBroker userBroker1 = new UserBroker("UserBroker1", SIMTag.RM_MODE_S);
		ResourceScaler resourceScaler = new ThresholdScaler(5, 0.5);
		SlotType slotType = new SlotType(1, 1000, 250, 50000);

		Workload wl = new Workload();
		
		List<Task> taskList1 = new ArrayList<Task>();
		List<Task> taskList2 = new ArrayList<Task>();
		for(int i=0; i<30; ++i){
			taskList1.add(new Task(i, 60));
		}
		for(int i=0; i<35; ++i){
			taskList2.add(new Task(i, 60));
		}		
		AnyJob xJob1 = new AnyJob(100, wl);
		Job job1 = new BatchJob(100, taskList1, slotType, xJob1);
		Job job2 = new BatchJob(100, taskList2, slotType, xJob1);
		xJob1.add(job1);
		xJob1.add(job2);
		
		List<Task> taskList3 = new ArrayList<Task>();
		List<Task> taskList4 = new ArrayList<Task>();
		for(int i=0; i<40; ++i){
			taskList3.add(new Task(i, 60));
		}
		for(int i=0; i<30; ++i){
			taskList4.add(new Task(i, 45));
		}
		AllJob xJob2 = new AllJob(150, wl);
		Job job3 = new BatchJob(150, taskList3, slotType, xJob2);
		Job job4 = new BatchJob(150, taskList4, slotType, xJob2);
		xJob2.add(job3);
		xJob2.add(job4);
		
		List<Task> taskList5 = new ArrayList<Task>();
		List<Task> taskList6 = new ArrayList<Task>();
		for(int i=0; i<25; ++i){
			taskList5.add(new Task(i, 50));
		}
		for(int i=0; i<30; ++i){
			taskList6.add(new Task(i, 45));
		}
		OrderJob xJob3 = new OrderJob(300, wl);
		Job job5 = new BatchJob(300, taskList5, slotType, xJob3);
		Job job6 = new BatchJob(300, taskList6, slotType, xJob3);
		xJob3.add(job5);
		xJob3.add(job6);
		
		wl.add(xJob1);
		wl.add(xJob2);
		wl.add(xJob3);
		
		userBroker1.init(new AFCFSScheduler("FCFS-Gang"), resourceScaler);
		User user = new User("user", wl);
		userBroker1.addUser(user);
		CloudSchedSIM.addRM(monolithicRM);
		CloudSchedSIM.addUserBroker(userBroker1);
		CloudSchedSIM.startSimulation();
	}

}
